﻿using System.Web.UI.WebControls;
using AjaxControlToolkit;
using VoterPicture = System.Web.UI.WebControls.Image;

namespace VotanetWebSite.Classes
{
    public sealed class CreateControl
    {
        public const string VALID_CHARS_TEXT = "qwertyuiopasdfghjklñzxcvbnmQWERTYUIOPASDFGHJKLÑZXCVBNM";
        public const string VALID_CHARS_EMAIL = "@.qwertyuiopasdfghjklñzxcvbnmQWERTYUIOPASDFGHJKLÑXCVBNM1234567890_";
        public const string VALID_CHARS_TELEPHONE = "1234567890";
        public const string REGULAR_EXPRESSION_PICTURE = "(.*).(.jpg|.JPG|.jpeg|.JPEG)$";
        public const string REGULAR_EXPRESSION_EMAIL = @"(^[0-9a-zA-Z]+(?:[._][0-9a-zA-Z]+)*)@([0-9a-zA-Z]+(?:[._-][0-9a-zA-Z]+)*\.[0-9a-zA-Z]{2,3})$";

        public static Button OfTypeButton(string id, string text)
        {
            Button btn = new Button();
            btn.ID = id;
            btn.Text = text;
            btn.CommandArgument = id;
            return btn;
        }

        public static Label OfTypeLabel(string id, string text, string cssClass)
        {
            Label label = new Label();
            label.ID = id;
            label.Text = text;
            label.CssClass = cssClass;
            return label;
        }

        public static VoterPicture OfTypeImagen(string id, string pictureName, string location)
        {
            VoterPicture img = new VoterPicture();
            img.ID = id;
            img.ImageUrl = location + pictureName;
            return img;
        }

        public static RadioButton OfTypeRadioButton(string id, string group)
        {
            RadioButton rd = new RadioButton();
            rd.ID = id;
            rd.GroupName = group;
            return rd;
        }

        public static TextBox OfTypeTexBox(string id, int large)
        {
            TextBox textBox = new TextBox();
            textBox.ID = id;
            textBox.MaxLength = large;
            return textBox;
        }

        public static RequiredFieldValidator OfTypeRequiredFieldValidator(string id, string controlToValidate, string message, string validationGroup)
        {
            RequiredFieldValidator valida = new RequiredFieldValidator();
            valida.ID = id;
            valida.ControlToValidate = controlToValidate;
            valida.ErrorMessage = message;
            valida.Display = ValidatorDisplay.None;
            valida.ValidationGroup = validationGroup;
            return valida;
        }

        public static FilteredTextBoxExtender OfTypeFilteredTextBoxExtender(string id, string controlToValidate, string validChar)
        {
            FilteredTextBoxExtender FiltroTxtNombre = new FilteredTextBoxExtender();
            FiltroTxtNombre.ID = id;
            FiltroTxtNombre.TargetControlID = controlToValidate;
            FiltroTxtNombre.ValidChars = validChar;
            FiltroTxtNombre.FilterMode = FilterModes.ValidChars;
            return FiltroTxtNombre;
        }

        public static ValidatorCalloutExtender OfTypeValidatorCalloutExtender(string id, string controlToValidate)
        {
            ValidatorCalloutExtender AjaxTxtNombre = new ValidatorCalloutExtender();
            AjaxTxtNombre.ID = id;
            AjaxTxtNombre.TargetControlID = controlToValidate;
            AjaxTxtNombre.PopupPosition = ValidatorCalloutPosition.BottomLeft;
            return AjaxTxtNombre;
        }

        public static FileUpload OfTypeFileUpload(string id)
        {
            FileUpload file = new FileUpload();
            file.Width = Unit.Pixel(205);
            file.ID = id;
            file.Style.Add("position","relative");
            return file;
        }

        public static RegularExpressionValidator OfTypeRegularExpressionValidator(string id, string controlToValidate, string expresion, string message, string validationGroup)
        {
            RegularExpressionValidator reg = new RegularExpressionValidator();
            reg.ID = id;
            reg.ValidationExpression = expresion;
            reg.ControlToValidate = controlToValidate;
            reg.ErrorMessage = message;
            reg.Display = ValidatorDisplay.None;
            reg.ValidationGroup = validationGroup;
            return reg;
        }

        public static DropDownList OfTypeDropDownList(string id)
        {
            ListItem[] items ={new ListItem("1"),
                               new ListItem("2"),
                               new ListItem("3"),
                               new ListItem("4"),
                               new ListItem("5"),
                               new ListItem("6"),
                               new ListItem("7"),
                               new ListItem("8"),
                               new ListItem("9")
                               };

            DropDownList ddl = new DropDownList();
            ddl.ID = id;
            ddl.Items.AddRange(items);
            return ddl;
        }

    }
}
